<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="HeaderInfo">

using System;
using System.Collections.Generic;
using System.Text;

using <xsl:value-of select="ProjectName"/>.Core.Interfaces;

namespace <xsl:value-of select="ProjectName"/>.Data.NHibernateDal
{
	<![CDATA[
	public abstract class DataObject<Type, ObjectIdType> : IDataObject<Type, ObjectIdType>
	{

		 /// <summary>
		/// Returns all of the objects of the Type
		/// </summary>
		List<Type> IDataObject<Type , ObjectIdType>.GetAll ( )
		{
		    return GetByCriteria ( );
		}


		/// <summary>
		/// Get an object by its ID
		/// </summary>
		Type IDataObject<Type , ObjectIdType>.GetId ( ObjectIdType id )
		{
		    return ( Type ) Session.Load ( typeof ( Type ) , id );
		}
		

		/// <summary>
		/// Get values with criteria
		/// </summary>
		/// <param name="criterion">criteria to get values by</param>
		public List<Type> GetByCriteria ( params NHibernate.Expression.ICriterion[] criterion )
		{
		    NHibernate.ICriteria criteria = Session.CreateCriteria ( typeof ( Type ) );

		    foreach ( NHibernate.Expression.ICriterion criterium in criterion )
		    {
			criteria.Add ( criterium );
		    }

		    return criteria.List<Type> ( ) as List<Type>;
		}
		


		/// <summary>
		/// Save the object
		/// </summary>
		Type IDataObject<Type , ObjectIdType>.Save ( Type obj )
		{
			Session.Save ( obj );
			return obj;
		}

		/// <summary>
		/// Can be called with objects that have generated ids for updating
		/// or creating new entries.
		/// </summary>
		Type IDataObject<Type , ObjectIdType>.SaveOrUpdate ( Type obj )
		{
			Session.SaveOrUpdate ( obj );
			return obj;
		}

		/// <summary>
		/// Delete the object
		/// </summary>
		void IDataObject<Type , ObjectIdType>.Delete ( Type obj )
		{
		    Session.Delete ( obj );
		}
		
		
		/// <summary>
		/// Clear the session cache
		/// </summary>
		public void Flush ( )
		{
			Session.Flush ( );
		}



		/// <summary>
		/// Exposes the ISession used within the DAO.
		/// </summary>
		private NHibernate.ISession Session
		{
		    get
		    {
			return SessionManager.Instance.GetSession ( );
		    }
		}

	}]]>
}

	</xsl:template>
	
	
	
</xsl:stylesheet>